{extend name="../../base/view/layout" /}
{block name="my_body"}
<div class="maincontent">
    <div class="maincontentinner">

        <form  enctype="multipart/form-data" method="post" action="<?php echo url('shop/Goods/goods_num',['id'=>$goods_id]);?>">
            <table  class="table table-bordered">
                <thead>
                <tr>
                    <?php
                 $count=0;
                 foreach($data as $k=>$v):
                    $count++;
                    ?>
                    <th  ><?php echo $k;?></th>
                    <?php endforeach;?>
                    <th  >库存</th>
                    <th  >商品价格</th>
                    <th  >促销价格</th>
                    <th  >会员价格</th>
                    <th  >商品重量</th>
                    <th  >操作</th>
                </tr>
                </thead>
                <tbody>
                <?php if($gnData):
        foreach($gnData as $k0=>$v0):
                ?>
                <tr>
                    <?php foreach($data as $k=>$v):?>
                    <td >
                        <select name="goods_attr_id[]" style="width:110px;">
                            <option value=''>-请选择-</option>
                            <?php foreach($v as $k1=>$v1):
                            $gaid=explode(',',$v0['goods_attr_id']);
                            if(in_array($v1['id'],$gaid))
                            $select="selected='selected'";
                            else
                            $select="";
                            ?>
                            <option value="<?php echo $v1['id'];?>" <?php echo $select;?> ><?php echo $v1['attr_value'];?></option>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <?php endforeach;?>
                    <input type="hidden" name="goods_id" value="<?php echo $goods_id;?>"  />
                    <td ><input type="text" name="goods_num[]"  value="<?php echo $v0['goods_number'];?>"/></td>
                    <td ><input type="text" name="goods_price[]"  value="<?php echo $v0['goods_price'];?>"/></td>
                    <td ><input type="text" name="promote_price[]"  value="<?php echo $v0['promote_price'];?>"/></td>
                    <td ><input type="text" name="member_price[]"  value="<?php echo $v0['member_price'];?>"/></td>
                    <td ><input type="text" name="goods_weight[]"  value="<?php echo $v0['goods_weight'];?>"/>&ensp;kg</td>
                    <td ><input type="button" name="" <?php if($k0==0) echo "value='增加'"; else echo "value='删除'";?> class='addnum' style='padding:4px;background:#eea236;color:#ffffff;border:0px;' /></td>
                </tr>
                <!--end-->
                <?php endforeach;?>
                </tbody>
                <?php else:?>
                <!--start-->
                <tbody>
                <tr>
                    <?php foreach($data as $k=>$v):?>
                    <td >
                        <select name="goods_attr_id[]" style="width:110px;">
                            <option value=''>-请选择-</option>
                            <?php foreach($v as $k1=>$v1):?>
                            <option value="<?php echo $v1['id'];?>"><?php echo $v1['attr_value'];?></option>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <?php endforeach;?>
                    <input type="hidden" name="goods_id" value="<?php echo $goods_id;?>" />
                    <td ><input type="text" name="goods_num[]" /></td>
                    <td ><input type="text" name="goods_price[]"  /></td>
                    <td ><input type="text" name="promote_price[]"  /></td>
                    <td ><input type="text" name="member_price[]"  /></td>
                    <td ><input type="text" name="goods_weight[]"  />&ensp;kg</td>
                    <td ><input type="button" name="" value='增加' class='addnum' style='padding:4px;background:#eea236;color:#ffffff;border:0px;' /></td>
                </tr>
                <!--end-->
                </tbody>
                <?php endif;?>
                <tbody>
                <tr>
                    <td colspan="<?php echo $count+6;?>" align="right"><input type='submit' value='提交' style="background:#46b8da;padding:5px 10px;color:#fff;margin-right:150px;border:0px;"/></td>
                </tr>
                </tbody>
            </table>
        </form>


    </div><!--maincontentinner-->
</div><!--maincontent-->
{/block}

{block name="my_js"}
<script>
    var $ = jQuery.noConflict();
    $('.addnum').click(function(){
        var opt=$(this).val();
        var tr=$(this).parent().parent();
        if(opt=="增加"){
            var newTr=tr.clone(true);
            newTr.find('select').val('');
            newTr.find("input[type='text']").val('');
            newTr.find("input[type='button']").val('删除');
            tr.after(newTr);
        }else{
            tr.remove();
        }
    })
</script>
{/block}
